﻿// Bing Maps ASP.NEt Control is a community project available under the Microsoft Public License (Ms-PL)
// Code is provided as is and with no warrenty – Use at your own risk
// View the project and the latest code at http://BingMapsASP.codeplex.com

using System.Collections.Generic;
using System.ComponentModel;
using System.Web.UI;
using Microsoft.Live.ServerControls.VE.Constants;

[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.View3D.js", "text/javascript")]
[assembly: WebResource("Microsoft.Live.ServerControls.VE.Extenders.View3D.debug.js", "text/javascript")]

namespace Microsoft.Live.ServerControls.VE.Extenders
{
    [ToolboxData(@"<{0}:View3D ID=""View3DExtender1"" runat=""server"" MapControlID="""" TargetControlID="""" ></{0}:View3D>")]
    public sealed class View3D : ExtenderBase
    {

        #region Properties

        /// <summary>
        /// The extender can either set to adjust any combination of values required
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue(View3DMode.AltitudeHeadingPitch)]
        [Description("The extender can either set to adjust any combination of values required")]
        public View3DMode Mode
        {
            get { return (View3DMode)(ViewState[View3DExtenderControlProperty.Mode] ?? View3DMode.AltitudeHeadingPitch); }
            set
            {
                ViewState[View3DExtenderControlProperty.Mode] = value;
            }
        }

        /// <summary>
        /// a double that represents the altitude (in meters) above the geoid.
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("0.0")]
        [Description("a double that represents the altitude (in meters) above the geoid.")]
        public double Altitude
        {
            get { return (double)(ViewState[View3DExtenderControlProperty.Altitude] ?? 0.0); }
            set
            {
                ViewState[View3DExtenderControlProperty.Altitude] = value;
            }
        }

        /// <summary>
        /// a double that represents the compass heading of the current map view.
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("0.0")]
        [Description("a double that represents the compass heading of the current map view.")]
        public double Heading
        {
            get { return (double)(ViewState[View3DExtenderControlProperty.Heading] ?? 0.0); }
            set
            {
                ViewState[View3DExtenderControlProperty.Heading] = value;
            }
        }

        /// <summary>
        /// a double that represents the pitch of the current map view.
        /// </summary>
        [Browsable(true)]
        [Category("Behaviour")]
        [DefaultValue("0.0")]
        [Description("a double that represents the pitch of the current map view.")]
        public double Pitch
        {
            get { return (double)(ViewState[View3DExtenderControlProperty.Pitch] ?? 0.0); }
            set
            {
                ViewState[View3DExtenderControlProperty.Pitch] = value;
            }
        }

        #endregion

        #region ExtenderControl Members

        protected override IEnumerable<ScriptDescriptor> GetScriptDescriptors(Control targetControl)
        {
            ScriptBehaviorDescriptor descriptor = new ScriptBehaviorDescriptor("Microsoft.Live.ClientControls.VE.Extenders.View3D", targetControl.ClientID);
            descriptor.AddProperty(View3DExtenderControlProperty.Mode, Mode);
            descriptor.AddProperty(View3DExtenderControlProperty.Altitude, Altitude);
            descriptor.AddProperty(View3DExtenderControlProperty.Heading, Heading);
            descriptor.AddProperty(View3DExtenderControlProperty.Pitch, Pitch);
            descriptor.AddProperty(ExtenderControlProperty.MapControlID, MapControlID);
            yield return descriptor;
        }

        protected override IEnumerable<ScriptReference> GetScriptReferences()
        {
            List<ScriptReference> descriptors = new List<ScriptReference>();
            descriptors.Add(new ScriptReference("Microsoft.Live.ServerControls.VE.Extenders.View3D.js", GetType().Assembly.FullName));
            return descriptors;
        }

        #endregion
    }
}
